package dmmm.shemes;

import java.awt.Point;
import java.util.ArrayList;

import dmmm.components.*;
import dmmm.gui.*;

public class Intr2 {

    private static AND AND1, AND2, AND3, AND4, AND5, AND6, AND7, AND8;
    private static OR OR1;
    private static CD CDP;
    private static CMP AB;
    private static GuiScheme gui;

    public static GuiScheme getGui() {
        return gui;
    }

    public static void init() {
        AND1 = new AND();
        AND2 = new AND();
        AND3 = new AND();
        AND4 = new AND();
        AND5 = new AND();
        AND6 = new AND();
        AND7 = new AND();
        AND8 = new AND(3);
        OR1 = new OR(7);
        CDP = new CD(8);
        AB = new CMP(3);
    }

    public static void connect() {
        AND1.setInputPin(0, Intr1.IMR7());
        AND1.setInputPin(1, Intr1.PRINTR7());

        AND2.setInputPin(0, Intr1.IMR6());
        AND2.setInputPin(1, Intr1.PRINTR6());

        AND3.setInputPin(0, Intr1.IMR5());
        AND3.setInputPin(1, Intr1.PRINTR5());

        AND4.setInputPin(0, Intr1.IMR4());
        AND4.setInputPin(1, Intr1.PRINTR4());

        AND5.setInputPin(0, Intr1.IMR3());
        AND5.setInputPin(1, Intr1.PRINTR3());

        AND6.setInputPin(0, Intr1.IMR2());
        AND6.setInputPin(1, Intr1.PRINTR2());

        AND7.setInputPin(0, Intr1.IMR1());
        AND7.setInputPin(1, Intr1.PRINTR1());

        CDP.setE(new Pin(true));
        CDP.setInputPin(0, new Pin(false));
        CDP.setInputPin(1, AND7.getOut(0));
        CDP.setInputPin(2, AND6.getOut(0));
        CDP.setInputPin(3, AND5.getOut(0));
        CDP.setInputPin(4, AND4.getOut(0));
        CDP.setInputPin(5, AND3.getOut(0));
        CDP.setInputPin(6, AND2.getOut(0));
        CDP.setInputPin(7, AND1.getOut(0));

        AB.setE(new Pin(true));
        AB.setPinA(0, CDP.getOut(0));
        AB.setPinA(1, CDP.getOut(1));
        AB.setPinA(2, CDP.getOut(2));
        AB.setPinB(0, Exec2.PSWL0());
        AB.setPinB(1, Exec2.PSWL1());
        AB.setPinB(2, Exec2.PSWL2());

        OR1.setInputPin(0, AND1.getOut(0));
        OR1.setInputPin(1, AND2.getOut(0));
        OR1.setInputPin(2, AND3.getOut(0));
        OR1.setInputPin(3, AND4.getOut(0));
        OR1.setInputPin(4, AND5.getOut(0));
        OR1.setInputPin(5, AND6.getOut(0));
        OR1.setInputPin(6, AND7.getOut(0));

        AND8.setInputPin(0, OR1.getOut(0));
        AND8.setInputPin(1, AB.getOut(0));
        AND8.setInputPin(2, Exec2.PSWI());

    }

    public static void gui() {
        GuiLine line; // Pomocna promenljiva
        gui = new GuiScheme("dmmm/dmmm/images/Intr2.png");

        ArrayList<ArrayList<Point>> sections;
        ArrayList<Point> points;


        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(219, 150));
        points.add(new Point(445, 150));
        points.add(new Point(445, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.IMR1());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 150));
        points.add(new Point(457, 150));
        points.add(new Point(457, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.PRINTR1());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 165));
        points.add(new Point(430, 165));
        points.add(new Point(430, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.PRINTR2());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 180));
        points.add(new Point(404, 180));
        points.add(new Point(404, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.PRINTR3());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 195));
        points.add(new Point(377, 195));
        points.add(new Point(377, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.PRINTR4());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 210));
        points.add(new Point(351, 210));
        points.add(new Point(351, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.PRINTR5());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 225));
        points.add(new Point(324, 225));
        points.add(new Point(324, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.PRINTR6());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 240));
        points.add(new Point(298, 240));
        points.add(new Point(298, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.PRINTR7());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(219, 165));
        points.add(new Point(419, 165));
        points.add(new Point(419, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.IMR2());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(219, 180));
        points.add(new Point(393, 180));
        points.add(new Point(393, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.IMR3());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(219, 195));
        points.add(new Point(366, 195));
        points.add(new Point(366, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.IMR4());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(219, 210));
        points.add(new Point(340, 210));
        points.add(new Point(340, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.IMR5());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(219, 225));
        points.add(new Point(313, 225));
        points.add(new Point(313, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.IMR6());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(219, 240));
        points.add(new Point(287, 240));
        points.add(new Point(287, 248));
        sections.add(points);
        line = new GuiLine(sections, Intr1.IMR7());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(292, 271));
        points.add(new Point(292, 422));
        points.add(new Point(332, 422));
        points.add(new Point(332, 456));
        sections.add(points);
        line = new GuiLine(sections, AND1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(319, 271));
        points.add(new Point(319, 414));
        points.add(new Point(347, 414));
        points.add(new Point(347, 456));
        sections.add(points);
        line = new GuiLine(sections, AND2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(345, 271));
        points.add(new Point(345, 407));
        points.add(new Point(362, 407));
        points.add(new Point(362, 456));
        sections.add(points);
        line = new GuiLine(sections, AND3.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(372, 271));
        points.add(new Point(372, 399));
        points.add(new Point(377, 399));
        points.add(new Point(377, 456));
        sections.add(points);
        line = new GuiLine(sections, AND4.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(398, 271));
        points.add(new Point(398, 399));
        points.add(new Point(393, 399));
        points.add(new Point(393, 456));
        sections.add(points);
        line = new GuiLine(sections, AND5.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(425, 271));
        points.add(new Point(425, 407));
        points.add(new Point(408, 407));
        points.add(new Point(408, 456));
        sections.add(points);
        line = new GuiLine(sections, AND6.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(451, 271));
        points.add(new Point(451, 414));
        points.add(new Point(423, 414));
        points.add(new Point(423, 456));
        sections.add(points);
        line = new GuiLine(sections, AND7.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(438, 448));
        points.add(new Point(438, 456));
        sections.add(points);
        line = new GuiLine(sections, new Pin(false));
        gui.addLine(line);


        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(254, 329));
        points.add(new Point(264, 329));
        points.add(new Point(264, 301));
        points.add(new Point(476, 301));
        sections.add(points);
        line = new GuiLine(sections, AND1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(254, 335));
        points.add(new Point(270, 335));
        points.add(new Point(270, 316));
        points.add(new Point(476, 316));
        sections.add(points);
        line = new GuiLine(sections, AND2.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(253, 341));
        points.add(new Point(275, 341));
        points.add(new Point(275, 331));
        points.add(new Point(476, 331));
        sections.add(points);
        line = new GuiLine(sections, AND3.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 346));
        points.add(new Point(252, 346));
        sections.add(points);
        line = new GuiLine(sections, AND4.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 361));
        points.add(new Point(275, 361));
        points.add(new Point(275, 352));
        points.add(new Point(253, 352));
        sections.add(points);
        line = new GuiLine(sections, AND5.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 377));
        points.add(new Point(270, 377));
        points.add(new Point(270, 358));
        points.add(new Point(254, 358));
        sections.add(points);
        line = new GuiLine(sections, AND6.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(476, 392));
        points.add(new Point(264, 392));
        points.add(new Point(264, 363));
        points.add(new Point(254, 363));
        sections.add(points);
        line = new GuiLine(sections, AND7.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(363, 503));
        points.add(new Point(363, 528));
        points.add(new Point(279, 528));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(363, 528));
        points.add(new Point(453, 528));
        sections.add(points);
        line = new GuiLine(sections, CDP.getOut(2));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(385, 503));
        points.add(new Point(385, 543));
        points.add(new Point(279, 543));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(385, 543));
        points.add(new Point(453, 543));
        sections.add(points);
        line = new GuiLine(sections, CDP.getOut(1));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(408, 503));
        points.add(new Point(408, 558));
        points.add(new Point(279, 558));
        sections.add(points);
        points = new ArrayList<Point>();
        points.add(new Point(407, 558));
        points.add(new Point(453, 558));
        sections.add(points);
        line = new GuiLine(sections, CDP.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(226, 528));
        points.add(new Point(234, 528));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWL2());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(226, 543));
        points.add(new Point(234, 543));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWL1());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(226, 558));
        points.add(new Point(234, 558));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWL0());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(256, 505));
        points.add(new Point(256, 409));
        points.add(new Point(217, 409));
        sections.add(points);
        line = new GuiLine(sections, AB.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(232, 346));
        points.add(new Point(224, 346));
        points.add(new Point(224, 403));
        points.add(new Point(217, 403));
        sections.add(points);
        line = new GuiLine(sections, OR1.getOut(0));
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(224, 422));
        points.add(new Point(224, 414));
        points.add(new Point(217, 414));
        sections.add(points);
        line = new GuiLine(sections, Exec2.PSWI());
        gui.addLine(line);

        sections = new ArrayList<ArrayList<Point>>();
        points = new ArrayList<Point>();
        points.add(new Point(194, 409));
        points.add(new Point(186, 409));
        sections.add(points);
        line = new GuiLine(sections, AND8.getOut(0));
        gui.addLine(line);

    }

    public static Pin irm1() {
        return AND7.getOut(0);
    }

    public static Pin irm2() {
        return AND6.getOut(0);
    }

    public static Pin irm3() {
        return AND5.getOut(0);
    }

    public static Pin irm4() {
        return AND4.getOut(0);
    }

    public static Pin irm5() {
        return AND3.getOut(0);
    }

    public static Pin irm6() {
        return AND2.getOut(0);
    }

    public static Pin irm7() {
        return AND1.getOut(0);
    }

    public static Pin prl0() {
        return CDP.getOut(0);
    }

    public static Pin prl1() {
        return CDP.getOut(1);
    }

    public static Pin prl2() {
        return CDP.getOut(2);
    }

    public static Pin printr() {
        return AND8.getOut(0);
    }
}
